package com.scbo.utility;

import java.util.ArrayList;
import java.util.List;

import com.scbo.DTO.ItemBO;
import com.scbo.main.R;

import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class ItemCreateArrayAdapter extends ArrayAdapter<ItemBO> {

	Context context = null;
	ArrayList<ItemBO> itemList = null;

	public ItemCreateArrayAdapter(Activity context, ArrayList<ItemBO> listItems) {
		super(context, R.layout.list_item_create, listItems);
		this.context = context;
		this.itemList = listItems;
		// TODO Auto-generated constructor stub
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		LayoutInflater inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		// LayoutInflater inflater = context.getLayoutInflater();
		View listView  = convertView;
		listView = inflater.inflate(R.layout.list_item_create, parent,
				false);
		TextView txtTimeShow = (TextView) listView
				.findViewById(R.id.txtTimeShow);
		TextView txtTextShow = (TextView) listView
				.findViewById(R.id.txtTextShow);
		ItemBO item = itemList.get(position);
		long milisecond = item.getTime();
		int minute = CalculateTime.convertToMinute(milisecond);
		int second = CalculateTime.convertToSecond(milisecond);
		Log.d("KHANHVQ", "getView = " + minute + ":" + second);
		txtTimeShow.setText(minute + ":" + second);
		txtTextShow.setText(item.getText());

		return listView;
	}

}
